﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          chi.zhang
        更新时间：      20141230
        用途：          生成应用服务器的function.sdf
        
        @author: huifang.wang
        @date:2015/11/2
        
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:variable name="MetadataTypeDefine" select="document('../model/0101_metadataTypeDefine.xml')"/>
	<xsl:result-document encoding="utf-8" method="text" href="./generate/appserver/ProcedureConfigSet.cpp">#include "ProcedureConfigSet.h"
ProcedureConfigSet::ProcedureConfigSet()
{
  <xsl:for-each select="Functions/Function">
  <xsl:variable name="FuncNo" select="@func_no"/>
  //p<xsl:value-of select="$FuncNo"/>:<xsl:value-of select="@func_name"/>
  <xsl:for-each select="Request">
  //Request
  ProcedureParameterType p<xsl:value-of select="$FuncNo"/>_in;
 strcpy(p<xsl:value-of select="$FuncNo"/>_in.procedureName, "<xsl:value-of select="$FuncNo"/>\0");
  p<xsl:value-of select="$FuncNo"/>_in.coloumnCount = <xsl:value-of select="count(child::Field)"/>;
<xsl:for-each select="Field">
<xsl:variable name="Name" select="@name"/>
<xsl:variable name="Position" select="position()"/>
  coloumnDefine p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>;
   strcpy(p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>.coloumnName, "<xsl:value-of select="$Name"/>\0");
  p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>.coloumnType = <xsl:for-each select="$MetadataTypeDefine//String[@typename=$Name]"> DB_COLOUMN_TYPE_CHAR;//<xsl:value-of select="@label"/>
  p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>.length = <xsl:value-of select="@length"/>;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Money[@typename=$Name]"> DB_COLOUMN_TYPE_DOUBLE;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Ratio[@typename=$Name]"> DB_COLOUMN_TYPE_DOUBLE;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Price[@typename=$Name]"> DB_COLOUMN_TYPE_DOUBLE;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Long[@typename=$Name]"> DB_COLOUMN_TYPE_INT;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Enum[@typename=$Name]"> DB_COLOUMN_TYPE_CHAR;
  p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>.length = 2;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Boolean[@typename=$Name]"> DB_COLOUMN_TYPE_CHAR;
  p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>.length = 1;
</xsl:for-each>  p<xsl:value-of select="$FuncNo"/>_in.define[<xsl:value-of select="number($Position)-1"/>] = p<xsl:value-of select="$FuncNo"/>_in_<xsl:value-of select="$Position"/>;
</xsl:for-each>
    in_parameter_map["<xsl:value-of select="$FuncNo"/>"] = p<xsl:value-of select="$FuncNo"/>_in;
  </xsl:for-each>
  <xsl:for-each select="Response">
  //Response
  ProcedureParameterType p<xsl:value-of select="$FuncNo"/>_out;
  strcpy(p<xsl:value-of select="$FuncNo"/>_out.procedureName , "<xsl:value-of select="$FuncNo"/>");
  p<xsl:value-of select="$FuncNo"/>_out.coloumnCount = <xsl:value-of select="count(child::Field)"/>;
<xsl:for-each select="Field">
<xsl:variable name="Name" select="@name"/>
<xsl:variable name="Position" select="position()"/>
  coloumnDefine p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>;
  strcpy(p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>.coloumnName, "<xsl:value-of select="$Name"/>\0");
  p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>.coloumnType = <xsl:for-each select="$MetadataTypeDefine//String[@typename=$Name]"> DB_COLOUMN_TYPE_CHAR;
  p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>.length = <xsl:value-of select="@length"/>;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Money[@typename=$Name]"> DB_COLOUMN_TYPE_DOUBLE;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Ratio[@typename=$Name]"> DB_COLOUMN_TYPE_DOUBLE;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Price[@typename=$Name]"> DB_COLOUMN_TYPE_DOUBLE;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Long[@typename=$Name]"> DB_COLOUMN_TYPE_INT;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Enum[@typename=$Name]"> DB_COLOUMN_TYPE_CHAR;
  p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>.length = 2;
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Boolean[@typename=$Name]"> DB_COLOUMN_TYPE_CHAR;
  p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>.length = 1;
</xsl:for-each>  p<xsl:value-of select="$FuncNo"/>_out.define[<xsl:value-of select="number($Position)-1"/>] = p<xsl:value-of select="$FuncNo"/>_out_<xsl:value-of select="$Position"/>;
</xsl:for-each>
   out_parameter_map["<xsl:value-of select="$FuncNo"/>"] = p<xsl:value-of select="$FuncNo"/>_out;
  </xsl:for-each>
  </xsl:for-each>
}

ProcedureConfigSet::~ProcedureConfigSet()
{
}

ProcedureParameterType ProcedureConfigSet::getInputDefine(string procedureName)
{
	return in_parameter_map[procedureName];
}
ProcedureParameterType ProcedureConfigSet::getOutputDefine(string procedureName)
{
	return out_parameter_map[procedureName];
}
</xsl:result-document>
	</xsl:template>  
</xsl:stylesheet>